home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / MiniGameManager.as < prev    next >
Text File  |  2007-09-27  |  8KB  |  247 lines

  1. class MiniGameManager extends Library.DispatcherBase
  2. {
  3.    static var TAK_FLY_START_X = 300;
  4.    static var TAK_FLY_START_Y = -50;
  5.    static var TAK_FOLLOW_Y = -150;
  6.    static var REMOVE_DEPTH = 1000000;
  7.    function MiniGameManager(__mcRef)
  8.    {
  9.       super();
  10.       this.mcRef = __mcRef;
  11.       MiniGameManager.oCtrl = this;
  12.       this.mcRef._y = Game.STAGE_HEIGHT;
  13.       this.aMoonStones = new Array();
  14.       this.aMiniStones = new Array();
  15.       this.nPosition = 0;
  16.       this.bScrollEnded = false;
  17.       this.bCalledEnd = false;
  18.       Main.__get__Instance().doAddListener(this);
  19.       this.doBuildLevel();
  20.       this.doStartWindFast();
  21.    }
  22.    static function get Instance()
  23.    {
  24.       return MiniGameManager.oCtrl;
  25.    }
  26.    function doSoundEvent(__nEvent, __oSound)
  27.    {
  28.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  29.       {
  30.          if(__oSound == this.oWindSlow)
  31.          {
  32.             delete this.oWindSlow;
  33.          }
  34.          else if(__oSound == this.oWindNormal)
  35.          {
  36.             delete this.oWindNormal;
  37.          }
  38.          else if(__oSound == this.oWindFast)
  39.          {
  40.             delete this.oWindFast;
  41.          }
  42.       }
  43.    }
  44.    function doStopWinds()
  45.    {
  46.       if(this.oWindSlow != undefined)
  47.       {
  48.          this.oWindSlow.doFadeTo(0);
  49.       }
  50.       if(this.oWindNormal != undefined)
  51.       {
  52.          this.oWindNormal.doFadeTo(0);
  53.       }
  54.       if(this.oWindFast != undefined)
  55.       {
  56.          this.oWindFast.doFadeTo(0);
  57.       }
  58.    }
  59.    function doStartWindSlow()
  60.    {
  61.       if(this.oWindSlow == undefined)
  62.       {
  63.          Library.Sound.SoundManager.isSoundPlaying("Wind_Slow.wav").oSound.doStop();
  64.          this.oWindSlow = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Slow.wav",0,999);
  65.          this.oWindSlow.doAddListener(this);
  66.          this.oWindSlow.setFadeRate(3);
  67.       }
  68.       this.oWindSlow.doFadeTo(100);
  69.       if(this.oWindNormal != undefined)
  70.       {
  71.          this.oWindNormal.doFadeTo(0);
  72.       }
  73.       if(this.oWindFast != undefined)
  74.       {
  75.          this.oWindFast.doFadeTo(0);
  76.       }
  77.    }
  78.    function doStartWindNormal()
  79.    {
  80.       if(this.oWindNormal == undefined)
  81.       {
  82.          Library.Sound.SoundManager.isSoundPlaying("Wind_Normal.wav").oSound.doStop();
  83.          this.oWindNormal = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Normal.wav",0,999);
  84.          this.oWindNormal.doAddListener(this);
  85.          this.oWindNormal.setFadeRate(3);
  86.       }
  87.       this.oWindNormal.doFadeTo(100);
  88.       if(this.oWindSlow != undefined)
  89.       {
  90.          this.oWindSlow.doFadeTo(0);
  91.       }
  92.       if(this.oWindFast != undefined)
  93.       {
  94.          this.oWindFast.doFadeTo(0);
  95.       }
  96.    }
  97.    function doStartWindFast()
  98.    {
  99.       if(this.oWindFast == undefined)
  100.       {
  101.          Library.Sound.SoundManager.isSoundPlaying("Wind_Fast.wav").oSound.doStop();
  102.          this.oWindFast = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Fast.wav",100,999);
  103.          this.oWindFast.doAddListener(this);
  104.          this.oWindFast.setFadeRate(3);
  105.       }
  106.       this.oWindFast.doFadeTo(100);
  107.       if(this.oWindNormal != undefined)
  108.       {
  109.          this.oWindNormal.doFadeTo(0);
  110.       }
  111.       if(this.oWindSlow != undefined)
  112.       {
  113.          this.oWindSlow.doFadeTo(0);
  114.       }
  115.    }
  116.    function doMinigameEnd()
  117.    {
  118.       if(!this.bCalledEnd)
  119.       {
  120.          this.bCalledEnd = true;
  121.          this.doStopWinds();
  122.          Game.__get__Instance().doMinigameEnd();
  123.       }
  124.    }
  125.    function doAddMiniStone(__mcObject)
  126.    {
  127.       var _loc2_ = new MiniStoneSky(__mcObject);
  128.       this.aMiniStones.push(_loc2_);
  129.    }
  130.    function doAddMoonStone(__mcObject)
  131.    {
  132.       var _loc2_ = new MoonStoneSky(__mcObject);
  133.       this.aMoonStones.push(_loc2_);
  134.    }
  135.    function doEnterFrame()
  136.    {
  137.       super.doEnterFrame();
  138.       if(!this.bPaused)
  139.       {
  140.          this.doScroll();
  141.          this.doCheckMoonstones();
  142.          this.doCheckMinistones();
  143.       }
  144.    }
  145.    function doDestroy()
  146.    {
  147.       super.doDestroy();
  148.       this.oWindFast.doStop();
  149.       this.oWindSlow.doStop();
  150.       this.oWindNormal.doStop();
  151.       delete this.oWindFast;
  152.       delete this.oWindSlow;
  153.       delete this.oWindNormal;
  154.       this.oTak.doDestroy();
  155.       delete this.oTak;
  156.       delete MiniGameManager.oCtrl;
  157.       Main.__get__Instance().doRemoveListener(this);
  158.       this.mcBg1.removeMovieClip();
  159.       this.mcBg2.removeMovieClip();
  160.       this.mcGame.removeMovieClip();
  161.       this.mcFront.removeMovieClip();
  162.    }
  163.    function doCheckMoonstones()
  164.    {
  165.       for(var _loc3_ in this.aMoonStones)
  166.       {
  167.          var _loc2_ = Library.Utils.MoreMath.getDistance(this.aMoonStones[_loc3_].Ref._x + this.aMoonStones[_loc3_].Ref._parent._x,this.aMoonStones[_loc3_].Ref._y + this.aMoonStones[_loc3_].Ref._parent._y,this.oTak.__get__Ref()._x,this.oTak.__get__Ref()._y);
  168.          if(_loc2_ < 75)
  169.          {
  170.             this.aMoonStones[_loc3_].onCatched();
  171.             Game.__get__Instance().onCatchMoonstone();
  172.             this.aMoonStones.splice(Number(_loc3_),1);
  173.          }
  174.       }
  175.    }
  176.    function doCheckMinistones()
  177.    {
  178.       for(var _loc3_ in this.aMiniStones)
  179.       {
  180.          var _loc2_ = Library.Utils.MoreMath.getDistance(this.aMiniStones[_loc3_].Ref._x + this.aMiniStones[_loc3_].Ref._parent._x,this.aMiniStones[_loc3_].Ref._y + this.aMiniStones[_loc3_].Ref._parent._y,this.oTak.__get__Ref()._x,this.oTak.__get__Ref()._y);
  181.          if(_loc2_ < 75)
  182.          {
  183.             this.aMiniStones[_loc3_].onCatched();
  184.             Game.__get__Instance().onCatchMiniStone();
  185.             this.aMiniStones.splice(Number(_loc3_),1);
  186.          }
  187.       }
  188.    }
  189.    function doScroll()
  190.    {
  191.       if(!this.bScrollEnded)
  192.       {
  193.          var _loc2_ = this.nPosition;
  194.          this.nTargetPosition = - (this.oTak.__get__Ref()._y - this.oTak.__get__FollowY());
  195.          if(this.nTargetPosition < 0)
  196.          {
  197.             this.nTargetPosition = 0;
  198.             this.nPosition = 0;
  199.             this.bScrollEnded = true;
  200.          }
  201.          else
  202.          {
  203.             this.nPosition += (this.nTargetPosition - this.nPosition) / 2;
  204.          }
  205.          this.mcBg1._y = this.nPosition * 0.2;
  206.          this.mcBg2._y = this.nPosition * 0.5;
  207.          this.mcGame._y = this.nPosition;
  208.          this.mcFront._y = this.nPosition * 1.1;
  209.       }
  210.    }
  211.    function doBuildLevel()
  212.    {
  213.       this.mcBg1 = this.mcRef.createEmptyMovieClip("mcBg1",1);
  214.       var _loc2_ = this.mcBg1.attachMovie("Panel_SkyBg","mcBg1_1",1);
  215.       _loc2_._y = - this.mcBg1._height;
  216.       this.mcBg2 = this.mcRef.createEmptyMovieClip("mcBg2",2);
  217.       var _loc3_ = 1;
  218.       while(_loc3_ <= 5)
  219.       {
  220.          _loc2_ = this.mcBg2.attachMovie("Panel_SkyBg2","mcBg2_" + _loc3_,_loc3_);
  221.          _loc2_._y = - _loc2_._height * _loc3_;
  222.          _loc3_ = _loc3_ + 1;
  223.       }
  224.       this.mcGame = this.mcRef.createEmptyMovieClip("mcGame",3);
  225.       _loc3_ = 1;
  226.       while(_loc3_ <= 4)
  227.       {
  228.          var _loc4_ = "Panel_SkyGame" + Library.Utils.MoreMath.getRandomRange(1,3);
  229.          _loc2_ = this.mcGame.attachMovie(_loc4_,"mcGame_" + _loc3_,_loc3_);
  230.          _loc2_._y = - _loc2_._height * _loc3_;
  231.          _loc3_ = _loc3_ + 1;
  232.       }
  233.       this.mcFront = this.mcRef.createEmptyMovieClip("mcFront",4);
  234.       _loc3_ = 1;
  235.       while(_loc3_ <= 14)
  236.       {
  237.          _loc2_ = this.mcBg2.attachMovie("Panel_SkyFront","mcFront_" + _loc3_,_loc3_);
  238.          _loc2_._y = - _loc2_._height * (_loc3_ * 0.99);
  239.          _loc3_ = _loc3_ + 1;
  240.       }
  241.       var _loc5_ = this.mcGame.attachMovie("Dynamic_TakFlying","mcTak",500);
  242.       _loc5_._x = MiniGameManager.TAK_FLY_START_X;
  243.       _loc5_._y = MiniGameManager.TAK_FLY_START_Y;
  244.       this.oTak = new TakFlying(_loc5_);
  245.    }
  246. }
  247.